#coding:utf8
from email.header import Header

from pyspark.sql import SparkSession

if __name__ == '__main__':
    # 构建SparkSession执行环境入口对象
    spark = SparkSession.builder.\
        appName("test").\
        master("local[*]").\
        getOrCreate()

    # 通过SparkSession可以获得SparkContent
    sc = spark.sparkContext

    df = spark.read.csv("../data/input/stu_score.txt",sep=',',header=False)
    df2 = df.toDF('id','name','score')
    df2.printSchema()
    df2.show()

    df2.createTempView("score")

    # sql风格
    spark.sql("""
        select * from score where name ='语文' limit 5
    """).show()

    # DSL风格
    df2.where("name = '语文'").limit(5).show()